// 固定资产管理
<template>
  <el-row class="drugStorage-body">
    <el-col :span="24">
      <TopManu></TopManu>
    </el-col>
    <el-col class="" :span="24">
      <el-col class="drugStorage-left" :span="6">
        <el-col :span="22">
          <el-button size="small" @click='centerDialogVisible=true,act=1'>新增</el-button>
          <el-button size="small" @click='centerDialogVisible=true,formdata=buildinfo,act=0'>编辑</el-button>
          <el-button size="small" @click='deletebiu(buildinfo.id)'>删除</el-button>
        </el-col>
        <el-col :span="22" style='margin-top:10px'>
          <div class="drugStorage-left-list" v-for="(item,index) in buildlist"
               :key='index' :style="
                  activity == index ? 'background:#aeecd1c2;' : ''
                " @click="Select(index)">
            <el-col :span="10">
              <img :src="his_19" alt="">
            </el-col>
            <el-col :span="14" class="list-text">
              <div>楼宇名称:{{ item.name }}</div>
              <div>层数:{{ item.floor_number }}层</div>
              <div>房间数:{{ item.room_number }}间</div>
              <div>说明：{{ item.remark }}</div>
            </el-col>
          </div>

        </el-col>
      </el-col>
      <el-col class="drugStorage-right" :span="18">
        <el-col :span="22">
          <el-button size="small" @click='centerDialogVisible2=true'>新增病区</el-button>
          <el-button size="small" @click='centerDialogVisible7=true'>设置房间等级</el-button>
        </el-col>
        <el-table
          :data="buildlist2"
          style="width: 100%">9
          <el-table-column
            prop="name"
            label="病区"
          >
          </el-table-column>
          <el-table-column
            prop="remark"
            label="备注"
          >
          </el-table-column>
          <el-table-column
            prop="get_user.real_name"
            label="管理员">
          </el-table-column>
          <el-table-column
            prop="sex"
            label="病区性别">
            <template slot-scope="scope">
              {{ scope.row.sex == 1 ? '男' : scope.row.sex == 2 ? '女' : '其他' }}
            </template>
          </el-table-column>
          <el-table-column

            label="操作"
          >
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">查看房间</el-button>
              <el-button type="text" size="small" @click='centerDialogVisible2=true,formdata=scope.row,act=0'>编辑
              </el-button>
              <el-button type="text" size="small" @click='deletebiu(scope.row.id)'>删除</el-button>

            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-col>
    <el-dialog :close-on-click-modal='false' title="房间管理" @close='qingchu' :visible.sync="canceldialogdeposit"
               width="70%">
      <el-col :span="22">
        <el-button size="small" @click='centerDialogVisible3=true'>新增病房</el-button>

      </el-col>
      <el-table
        max-height="350"
        :data="buildlist3"
        style="width: 100%">
        <el-table-column
          prop="name"
          label="病房"
        >
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
        >
        </el-table-column>
        <el-table-column
          prop="get_user.real_name"
          label="管理员">
        </el-table-column>
        <el-table-column
          prop="bxy_levelname"
          label="房间等级">
        </el-table-column>


        <el-table-column

          label="操作"
        >
          <template slot-scope="scope">
            <el-button @click="handleClick2(scope.row.id)" type="text" size="small">查看床位</el-button>
            <el-button type="text" size="small" @click='centerDialogVisible3=true,formdata=scope.row,act=0'>编辑
            </el-button>
            <el-button type="text" size="small" @click='deletebiu(scope.row.id)'>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="canceldialogdeposit = false">取 消</el-button>

      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal='false' title="病床管理" @close='qingchu' :visible.sync="canceldialogdeposit1"
               width="70%">
      <el-col :span="22">
        <el-button size="small" @click='centerDialogVisible4=true,fangjianb=1,formdata2={room_id:formdata2.room_id}'>新增病床</el-button>

      </el-col>
      <el-table
        :data="benlist"
        style="width: 100%">
        <el-table-column
          prop="name"
          label="病床"
        >
        </el-table-column>

        <el-table-column
          prop="get_user.real_name"
          label="管理员">
        </el-table-column>


        <el-table-column

          label="操作"
        >
          <template slot-scope="scope">

            <el-button type="text" size="small" @click='centerDialogVisible4=true,formdata2=scope.row,fangjianb=0'>编辑
            </el-button>
            <el-button type="text" size="small" @click='deleteben(scope.row.id)'>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="canceldialogdeposit1 = false">取 消</el-button>

      </div>
    </el-dialog>
    <!-- 添加楼宇 -->
    <el-dialog :close-on-click-modal='false'
               title="楼宇"
               :visible.sync="centerDialogVisible"
               width="30%"
               center
               @close='qingchu'>
      <el-form ref="form" :model="formdata" label-width="80px">
        <el-form-item label="楼宇名称">
          <el-input v-model="formdata.name"></el-input>
        </el-form-item>
        <el-form-item label="楼宇备注">
          <el-input v-model="formdata.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="addsysbuild(1)">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 添加病区 -->
    <el-dialog :close-on-click-modal='false'
               title="病区"
               :visible.sync="centerDialogVisible2"
               width="30%"
               center
               @close='qingchu'>

      <el-form ref="form" :model="formdata" label-width="80px">
        <el-form-item label="病区名称">
          <el-input v-model="formdata.name"></el-input>
        </el-form-item>
        <el-form-item label="病区备注">
          <el-input v-model="formdata.remark"></el-input>
        </el-form-item>
        <el-form-item label="病区性别">
          <el-select v-model="formdata.sex" placeholder="病区性别">
            <el-option label="其他" value=""></el-option>
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible2 = false">取 消</el-button>
    <el-button type="primary" @click="addsysbuild(2)">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 添加病区 -->
    <el-dialog :close-on-click-modal='false'
               title="房间"
               :visible.sync="centerDialogVisible3"
               width="30%"
               center
               @close='qingchu'>

      <el-form ref="form" :model="formdata" label-width="80px">
        <el-form-item label="房间名称">
          <el-input v-model="formdata.name"></el-input>
        </el-form-item>
        <el-form-item label="房间备注">
          <el-input v-model="formdata.remark"></el-input>
        </el-form-item>
        <el-form-item label="房间等级">
          <el-select
            v-model="formdata.bxy_level"
            placeholder="房间等级"
          >
            <el-option
              v-for="item in ben_lv"
              :key="item.name"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>

        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible3 = false">取 消</el-button>
    <el-button type="primary" @click="addsysbuild(3)">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 添加床 -->
    <el-dialog :close-on-click-modal='false'
               title="床位"
               :visible.sync="centerDialogVisible4"
               width="30%"
               center
               @close='qingchu'>

      <el-form ref="form" :model="formdata2" label-width="80px">
        <el-form-item label="床位名称">
          <el-input v-model="formdata2.name"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible4 = false">取 消</el-button>
    <el-button type="primary" @click="addben()">确 定</el-button>
  </span>
    </el-dialog>
    <!-- //房间等级 -->
    <el-dialog
      :fullscreen='true'
      :close-on-click-modal='false'
      title="房间等级"
      :visible.sync="centerDialogVisible7"
      width="70%"
      center
      @close='qingchu'>
      <el-row>
        <el-col :span="24">

          <el-form ref="form" :model="fromdata3" label-width="80px">
          <el-col :span="6">
              <el-form-item label="收费项">
                <el-select
                  v-model="fromdata3.fee_id"
                  placeholder="收费项"
                  @change="xuanzefee"
                >
                  <el-option
                    v-for="item in benfee"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>

              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单价">
                <el-input v-model="fromdata3.price" type="number"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="收费次数">
                <el-input v-model="fromdata3.number" type="number"></el-input>
              </el-form-item>
            </el-col>
            
            <el-col :span="6">
              <el-form-item label="">
                <el-button size="small" @click='addfee()'>添加</el-button>

              </el-form-item>
            </el-col>

          </el-form>
        </el-col>
        <el-col :span="4">
          <el-menu
            :default-active="0"
            class="el-menu-vertical-demo"
            @open="handleNodeClick"
            @close="handleClose">

            <el-menu-item v-for="(item,index) in ben_lv" :key="index" @click="handleNodeClick(item)" :index="index">
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item.name }}</span>
            </el-menu-item>


          </el-menu>

          <!-- <el-tree :data="ben_lv" :props="defaultProps" @node-click="handleNodeClick(item)"></el-tree> -->
        </el-col>
        <el-col :span="18">
          <el-table
            :data="benfeelist"
            style="width: 100%">
            <el-table-column
              prop="fee.name"
              label="收费项"
            >
            </el-table-column>

            <el-table-column
              prop="price"
              label="费用金额">
            </el-table-column>
            <el-table-column
              prop="number"
              label="收费次数">
            </el-table-column>
              <el-table-column
              prop="fee.unit"
              label="收费单位">
            </el-table-column>

            <el-table-column

              label="操作"
            >
              <template slot-scope="scope">


                <el-button type="text" size="small" @click='deletebenfee(scope.row.id)'>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible7 = false">取 消</el-button>
        <!-- <el-button type="primary" @click="addben()">确 定</el-button> -->
  </span>
    </el-dialog>
  </el-row>
</template>

<script>
import FromList from "@/forComponents/fromList/fromList"
import TopManu from "@/components/TopMenu"
import his_19 from "@/assets/his_19.png"
import {
  getBuild, addsysbuild, upsysbuild, deletesysbuild, getBed, createBed,
  updateBed, deleteBed, getRoomLevel,
} from "@/api/assets"
import {getAdviceFee, getRoomLevelProject, deleteRoomLevelProject, createRoomLevelProject} from '@/api/zhuyanre'

export default {
  name: "fixedAssets",
  data() {
    return {
      activity: 0,
      his_19: his_19,
      leftValue: "",
      formInline: {
        rightKeyValue: "",
        rightRadio: "0"
      },
      buildinfo: {},
      buildlist: [],
      buildlist2: [],
      buildlist3: [],
      canceldialogdeposit: false,
      canceldialogdeposit1: false,
      centerDialogVisible: false,
      centerDialogVisible2: false,
      centerDialogVisible3: false,
      centerDialogVisible4: false,
      centerDialogVisible7: false,
      formdata: {
        name: '',
        level: '',
        pid: '',
        remark: '',
        sex: '',
        bxy_level: ''
      },
      formdata2: {
        name: '',
        room_id: '',
        icu_id: '',
        build_id: '',
      },
      fromdata3: {
        pid: '',
        fee_id: '',
        price: '',
        number: '',
        type: '',
      },
      benlist: [],
      act: 1,
      binid: '',
      ben_lv: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      benfee: [],
      benfeelist: [],

    }
  },
  mounted() {
    this.getBuild()
    this.getBed_lv()

  },
  methods: {
    getBed_lv() {
      getRoomLevel().then(res => {
        this.ben_lv = res.data
        this.fromdata3.pid = res.data[0].id
        this.getRoomLevelProject()
      })
      this.getgetAdviceFeeItem()
    },
    getRoomLevelProject() {
      getRoomLevelProject({id: this.fromdata3.pid}).then(res => {
        this.benfeelist = res.data
      })
    },
    getgetAdviceFeeItem() {
      getAdviceFee({page: 1, limit: 200, type: '1'}).then(res => {
        for (let i = 0; i < res.data.list.length; i++) {
          if (res.data.list[i].fee_category.id == 11) {
            this.benfee.push(res.data.list[i])
            console.log(this.benfee)
          }

        }

      })
    },
    handleNodeClick(item) {
      this.fromdata3.pid = item.id
      this.getRoomLevelProject(item.id)
    },
    addfee() {
      createRoomLevelProject(this.fromdata3).then(res => {
        this.getRoomLevelProject(this.fromdata3.pid)
      })
    },
    xuanzefee(e) {
      console.log(e)
      for (let i = 0; i < this.benfee.length; i++) {
        if (this.benfee[i].id == e) {
          console.log(this.benfee[i].id)
          this.fromdata3.price = this.benfee[i].price
        }

      }
    },
    deletebenfee(id) {
      deleteRoomLevelProject({id: id}).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "删除成功",
            type: "success"
          });
          this.getRoomLevelProject(this.fromdata3.pid)
        }
      })
    },
    //查看床位
    handleClick2(row) {
      this.canceldialogdeposit1 = true
      this.formdata2.room_id = row
      console.log(row)
      getBed({room_id: row, build_id: this.buildinfo.id, icu_id: this.binid}).then(res => {
        this.benlist = res.data.list
      })
    },
    //查看房间
    handleClick(row) {
      this.canceldialogdeposit = true
      this.binid = row.id
      console.log(this.binid)
      this.getBuild3(row.id)
    },
    //  切换楼
    Select(i) {
      this.buildinfo = this.buildlist[i]
      this.activity = i
      this.getBuild2(this.buildinfo.id)
    },
    //获取楼
    getBuild() {
      var data_t = {
        level: '1',
        pid: ''
      }
      getBuild(data_t).then(res => {
        console.log(res)
        this.buildlist = res.data.list
        this.buildinfo = this.buildlist[0]
        this.getBuild2(this.buildinfo.id)
      })
    },
    //获取病区
    getBuild2(id) {
      var data_t = {
        level: '2',
        pid: id
      }
      getBuild(data_t).then(res => {
        console.log(res)
        this.buildlist2 = res.data.list


      })
    },
    //获取房
    getBuild3(id) {
      var data_t = {
        level: '3',
        pid: id,
        limit:1000000,
      }
      getBuild(data_t).then(res => {
        console.log(res)
        this.buildlist3 = res.data.list
        for (let i = 0; i < this.buildlist3.length; i++) {
          this.buildlist3[i].bxy_levelname = this.maplv(this.buildlist3[i].bxy_level)

        }

      })
    },
    maplv(num) {

      var art = "";
      for (var i in this.ben_lv) {
        if (this.ben_lv[i].id == num) {
          art = this.ben_lv[i].name;
          return art;
        }
      }
    },

    //添加编辑/楼/病区/房
    addsysbuild(i) {
      var data = this.formdata
      data.level = i
      if (!data.id) {
        if (i == 1) {
          data.pid = 0
          addsysbuild(data).then(res => {
            console.log(data)
            if (res.code == 200) {

              this.getBuild()
              this.centerDialogVisible = false
              this.$refs['form'].resetFields()
            }
          })
        } else if (i == 2) {
          data.pid = this.buildinfo.id
          addsysbuild(data).then(res => {
            console.log(data)
            if (res.code == 200) {
              this.getBuild2(this.buildinfo.id)
              this.centerDialogVisible2 = false

              this.$refs['form'].resetFields()
            }
          })
        } else if (i == 3) {

          data.pid = this.binid
          console.log(data)
          addsysbuild(data).then(res => {

            if (res.code == 200) {

              this.getBuild3(this.binid)
              this.centerDialogVisible3 = false
              this.$refs['form'].resetFields()
            }
          })
        }


      } else {
        upsysbuild(data).then(res => {
          console.log(data)
          if (res.code == 200) {
            this.centerDialogVisible = false
            this.centerDialogVisible2 = false
            this.centerDialogVisible3 = false
            this.getBuild2(this.buildinfo.id)
            this.getBuild3(this.binid)
            this.getBuild()

            this.$refs['form'].resetFields()
          }
        })
      }

    },
    //删除/楼/病区/房
    deletebiu(id) {
      this.$confirm('是否继续删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletesysbuild({id: id}).then(res => {
          this.getBuild()

          this.getBuild3(this.binid)
          this.activity = 0
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //删除床位
    deleteben(id) {
      this.$confirm('是否继续删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteBed({id: id}).then(res => {
          this.getBed()
          this.centerDialogVisible4 = false
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    //添加编辑床位
    addben() {
      var data = this.formdata2
      if (!data.id) {
        data.icu_id = this.binid
        data.build_id = this.buildinfo.id


        createBed(data).then(res => {
          this.getBed()
          this.centerDialogVisible4 = false
          this.$message({
            type: 'success',
            message: '添加成功'
          });
        })
      } else {

        updateBed(data).then(res => {
          this.getBed()
          this.$message({
            type: 'success',
            message: '编辑成功'
          });
          this.centerDialogVisible4 = false
        })
      }

    },
    //获取床位
    getBed() {
      console.log(this.formdata2.room_id)
      getBed({room_id: this.formdata2.room_id, build_id: this.buildinfo.id, icu_id: this.binid}).then(res => {
        this.benlist = res.data.list
      })
    },
    qingchu() {
      this.$refs['form'].resetFields()
      this.formdata = {
        name: '',
        level: '',
        pid: '',
        remark: '',
        sex: '',
        bxy_level: ''
      },
        console.log(1)
    }
  },
  components: {
    FromList,
    TopManu,
  }
}
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
